package repository

import (
	"context"
	"onvif_server/internal/model"
	"time"
)

type JobRepository interface {
	Create(ctx context.Context, m *model.Job) error
	DeleteByIDs(ctx context.Context, ids []int) error
}

func NewJobRepository(r *Repository) JobRepository {
	return &jobRepository{
		Repository: r,
	}
}

type jobRepository struct {
	*Repository
}

func (r *jobRepository) Create(ctx context.Context, m *model.Job) error {
	if m.RunAt.IsZero() {
		m.RunAt = time.Now()
	}
	return r.DB(ctx).Create(m).Error
}

func (r *jobRepository) DeleteByIDs(ctx context.Context, ids []int) error {
	return r.DB(ctx).Delete(&model.Job{}, ids).Error
}
